package com.concerneyes.mine.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.concerneyes.R;

import java.util.ArrayList;

import stickylistheaders.StickyListHeadersAdapter;


public class StickyListAdapter extends BaseAdapter implements StickyListHeadersAdapter {

    private ArrayList<String> list;
    private Context mContext;

    public void init(Context context, ArrayList<String> list) {
        this.list = list;
        this.mContext = context;
        mContext = context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_sticky_item, null);
            viewHolder.mTitle = (TextView) convertView.findViewById(R.id.title);
            viewHolder.mDate = (TextView) convertView.findViewById(R.id.date);
            viewHolder.mLeftMoney = (TextView) convertView.findViewById(R.id.left_money);
            viewHolder.mInfo = (TextView) convertView.findViewById(R.id.info);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        if (position%7 == 0){
            viewHolder.mInfo.setTextColor(mContext.getResources().getColor(R.color.app_red));
            viewHolder.mInfo.setText("+15.00");
        }
        return convertView;
    }

    @Override
    public View getHeaderView(int position, View convertView, ViewGroup parent) {

        HeaderViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new HeaderViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_head_item, null);
            viewHolder.mHeadTitle = (TextView) convertView.findViewById(R.id.head_title);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (HeaderViewHolder) convertView.getTag();
        }
        viewHolder.mHeadTitle.setText(position/10 +"月份");
        return convertView;
    }

    @Override
    public long getHeaderId(int position) {
        return position / 10 + 0x1234;
    }


    class ViewHolder {
        TextView mTitle;
        TextView mDate;
        TextView mLeftMoney;
        TextView mInfo;
    }

    class HeaderViewHolder {
        TextView mHeadTitle;
    }
}
